﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;
using System.IO;
using System.Net.NetworkInformation;
using Microsoft.Phone.Shell;

namespace ontheroad
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            WebClient wcf = new WebClient();
            App.traf = new Traffy();
            wcf.DownloadStringAsync(App.traf.requestrd);
            wcf.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wcf_DownloadStringCompleted);
            
        }

        void wcf_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            //mainappbar.IsVisible
            waitScr.Visibility = Visibility.Collapsed;
            try
            {
                App.traf.getsessionkey(e.Result);
            }
            catch (WebException)
            {
                MessageBox.Show("Please check your internet connection.");
                NavigationService.GoBack();
                return;
            }
            catch (Exception)
            {
                MessageBox.Show("Server connection failed, Please wait a minute and try again.");
                NavigationService.GoBack();
                return;
            }
        }

        private void helpbut_Click(object sender, System.EventArgs e)
        {
        	// TODO: Add event handler implementation here.
			NavigationService.Navigate(new Uri("/about.xaml",UriKind.RelativeOrAbsolute));
        }

        
    }
}
